package com.yuju.account.dao.impl;


import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.yuju.account.dao.IUnitAccountDao;
import com.yuju.account.dao.entity.UnitAccount;
import com.yuju.account.dao.mapper.UnitAccountMapper;
import com.yuju.account.model.UnitAccountModel;
import com.yuju.common.PageModel;
import com.yuju.common.core.dao.AbstractBaseDao;
import com.yuju.persist.base.mapper.BaseMapper;

/**
 * 类名：UnitAccountDaoImpl  <br />
 *
 * 功能：
 *
 * @author : jiaokn <br />
 * @Date : 2017年11月27日 上午10:24:58  <br />
 * @version : 1.1 <br />
 */
@Repository
public class UnitAccountDaoImpl extends AbstractBaseDao<UnitAccountModel, UnitAccount, String> implements IUnitAccountDao {
	
	@Autowired
	private UnitAccountMapper unitAccountMapper;
	
	@Override
	public BaseMapper<UnitAccount, String> getMapper() {
		// TODO Auto-generated method stub
		return unitAccountMapper;
	}

	@Override
	public int updateProtocolBalance(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return unitAccountMapper.updateProtocolBalance(map);
	}

	@Override
	public int updateAgentBalance(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return unitAccountMapper.updateAgentBalance(map);
	}

	@Override
	public PageModel pageListUnitAccount(UnitAccountModel unitAccountModel, Integer currentPage, Integer rows) {
		PageModel pageModel = new PageModel(currentPage, rows);
		Map<Object, Object> map = getBeanMap(unitAccountModel, currentPage, rows);
		// 获得总数
		Integer total = countByMap(map);
		if (total == null || total == 0) {
			return null;
		}
		// 设置总记录数到返回结果中
		pageModel.setTotal(total);
		
		List<UnitAccount> list = unitAccountMapper.listUnitAccount(map);
		List<UnitAccountModel> modelList = convertP2M(list);
		pageModel.setRows(modelList);
		return pageModel;
	}

	@Override
	public Integer countByMap(Map<Object, Object> map) {
		return unitAccountMapper.countByMap(map);
	}

	@Override
	public PageModel listUnitAccountAndSum(UnitAccountModel unitAccountModel, Integer currentPage, Integer rows) {
		PageModel pageModel = new PageModel(currentPage, rows);
		Map<Object, Object> map = getBeanMap(unitAccountModel, currentPage, rows);
		Integer total = sumCountByMap(map);
		if (total == null || total == 0) {
			return null;
		}
		pageModel.setTotal(total);
		List<UnitAccount> list = unitAccountMapper.listUnitAccountAndSum(map);
		List<UnitAccountModel> modelList = convertP2M(list);
		pageModel.setRows(modelList);
		
		return pageModel;
	}

	@Override
	public Integer sumCountByMap(Map<Object, Object> map) {
		return unitAccountMapper.sumCountByMap(map);
	}

	@Override
	public List<UnitAccount> listUnitAccount(UnitAccountModel unitAccountModel) {
		Map<Object, Object> map = getBeanMap(unitAccountModel);
		return unitAccountMapper.listUnitAccount(map);
	}

	@Override
	public PageModel listUnitAccountSS(UnitAccountModel unitAccountModel, Integer currentPage, Integer rows) {
		PageModel pageModel = new PageModel(currentPage, rows);
		Map<Object, Object> map = getBeanMap(unitAccountModel,currentPage, rows);
		Integer total = countSSByMap(map);
		if (total == null || total == 0) {
			pageModel.setTotal(total);
			return pageModel;
		}
		pageModel.setTotal(total);
		List<UnitAccount> list = unitAccountMapper.listUnitAccountSS(map);
		List<UnitAccountModel> modelList = convertP2M(list);
		pageModel.setRows(modelList);
		return pageModel;
	}

	@Override
	public Integer countSSByMap(Map<Object, Object> map) {
		return unitAccountMapper.countSSByMap(map);
	}

	@Override
	public Map<Object, Object> getYSK(UnitAccountModel unitAccountModel) {
		Map<Object, Object> map = getBeanMap(unitAccountModel);
		return unitAccountMapper.getYSK(map);
	}

	@Override
	public List<UnitAccountModel> listUnitAccountSSNoPage(UnitAccountModel unitAccountModel) {
		return convertP2M(unitAccountMapper.listUnitAccountSS(getBeanMap(unitAccountModel)));
	}

	@Override
	public BigDecimal listUnitAccountSum(UnitAccountModel unitAccountModel) {
		return unitAccountMapper.listUnitAccountSum(getBeanMap(unitAccountModel));
	}
	

	

}
